package com.c.ctgproject.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.EditText
import android.widget.TextView
import androidx.appcompat.widget.LinearLayoutCompat
import androidx.fragment.app.FragmentActivity
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.c.ctgproject.R
import com.c.ctgproject.base.BaseRecyclerViewAdapter
import com.c.ctgproject.entity.HandlerBatteryEntity
import com.c.ctgproject.entity.guang.CarInfoEntityV2
import com.c.ctgproject.enum.DictionaryMenuEnum
import com.c.ctgproject.ui.collect.DictionaryMenuActivity
import com.c.ctgproject.ui.collect.HandlerBatteryViewModel
import com.c.ctgproject.utils.*
import com.c.ctgproject.wiget.common.CarInfoLayout
import com.lwkandroid.widget.ninegridview.NineGridBean
import com.lwkandroid.widget.ninegridview.NineGridView

class BatteryRvAdapter(private val context: FragmentActivity, private val mList: ArrayList<CarInfoEntityV2.DataBean.BatteryInfo>) : BaseRecyclerViewAdapter(context, mList) {
    override fun createViewHolder(parent: ViewGroup): RecyclerView.ViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.item_battery_list, parent, false)
        return MyViewHolder(view)
    }

    override fun handlerData(holder: RecyclerView.ViewHolder, position: Int) {
        if (holder is MyViewHolder) {
            val data = mList[position]
            holder.mContainer.addView(CarInfoLayout(context, "电池名称", data.batteryName.noDataHandler()))
            holder.mContainer.addView(CarInfoLayout(context, "电池编码", data.batteryCode.noDataHandler()))
            holder.mContainer.addView(CarInfoLayout(context, "电池自编码", data.batterySelfCode.noDataHandler()))
            holder.mContainer.addView(CarInfoLayout(context, "电池数量", data.count.noDataHandler()))
            holder.mContainer.addView(CarInfoLayout(context, "模组个数", data.moduleCount.noDataHandler()))
            holder.mContainer.addView(CarInfoLayout(context, "重量KG", data.weight.noDataHandler()))
            holder.mContainer.addView(CarInfoLayout(context, "容量Ah", data.capacityAh.noDataHandler()))
            holder.mContainer.addView(CarInfoLayout(context, "电压V", data.voltage.noDataHandler()))
            holder.mContainer.addView(CarInfoLayout(context, "容量Kwh", data.capacityKwh.noDataHandler()))
            holder.mContainer.addView(CarInfoLayout(context, "备注", data.remark.noDataHandler()))
            data.batteryPictures?.let {
                val adapter = ImageCommonRvAdapter(context,it )
                holder.mContainer.addView(CarInfoLayout(context, "电池拆解", ""))
                holder.mBatteryImageRV.visibility=View.VISIBLE
                holder.mBatteryImageRV.adapter = adapter
                holder.mBatteryImageRV.layoutManager = GridLayoutManager(context, 3, GridLayoutManager.VERTICAL, false)
            }
        }
    }


    inner class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val mContainer: LinearLayoutCompat = view.findViewById(R.id.mContainer)
        val mBatteryImageRV:RecyclerView=view.findViewById(R.id.mBatteryImageRV)
    }
}